<template>
	<view class="content" v-if="pageshow">
		<view class="padding">
			<!-- 1=已取消,1=待付款,3=待服务,4=服务中,5=待评价,6=已完成 -->
			<view class="bigtext" v-show="orderDetail.state==-1">已取消</view>
			<view class="bigtext" v-show="orderDetail.state==1">待付款</view>
			<view class="bigtext" v-show="orderDetail.state==3">待服务</view>
			<view class="bigtext" v-show="orderDetail.state==4">服务中</view>
			<view class="bigtext" v-show="orderDetail.state==5">待评价</view>
			<view class="bigtext" v-show="orderDetail.state==6">已完成</view>
			<view class="bigtext" v-show="orderDetail.state==8">已退款</view>
			<view class="strongtext" v-show="orderDetail.state==-1">您已取消此订单~</view>
			<view class="strongtext" v-show="orderDetail.state==3">等待服务中~</view>
			<view class="strongtext" v-show="orderDetail.state==5">期待您的评价~</view>
			<view class="strongtext" v-show="orderDetail.state==6">订单已完成，感谢您的支持~</view>
			<!-- 商家信息 -->
			<view class="padding ffffff border_2 margin_top">
				<view class="flexbetween">
					<view class="flexleft">
						<view class="imgBox margin_right2">
							<image :src="orderDetail.seller.avatar" mode="widthFix"></image>
						</view>
						<view class="color_ling text_six">{{orderDetail.seller.nickname}}</view>
					</view>
				</view>
			</view>
			<!-- 商品 -->
			<view class="ffffff padding border_2 margin_top">
				<view class="text_x color_ling">订单商品</view>
				<view class="margin_top">
					<view class="flexbetween">
						<view class="shilitu">
							<image :src="orderDetail.service_image_text" mode="widthFix"></image>
						</view>
						<view class="" style="width: 74%;">
							<view class="ershib yhxiank">{{orderDetail.service_name}}</view>
							<view class="flexbetween margin_top6">
								<view class="qianshu">¥{{orderDetail.total_price}}</view>
								<view class="shuliang">X1</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<!-- 商品详情 -->
			<view class="paddingbom">
				<view class="ffffff padding border_2 margin_top">
					<view class="flexbetween">
						<view class="tuihuo">商品金额</view>
						<view class="text_x" style="color:rgba(243, 39, 28, 1);">¥{{orderDetail.total_price}}</view>
					</view>
					<view class="flexbetween margin_top">
						<view class="tuihuo">订单编号</view>
						<view class="huisetext">{{orderDetail.order_no}}</view>
					</view>
					<view class="flexbetween margin_top">
						<view class="tuihuo">下单时间</view>
						<view class="huisetext">{{orderDetail.createtime_text}}</view>
					</view>
					<view class="flexbetween margin_top">
						<view class="tuihuo">支付方式</view>
						<view class="huisetext">{{orderDetail.pay_type_text}}</view>
					</view>
					<view class="flexbetween margin_top" v-if="orderDetail.remarks">
						<view class="tuihuo">备注</view>
						<view class="huisetext">{{orderDetail.remarks}}</view>
					</view>

				</view>
			</view>
			<!-- 固定底部 -->
			<view class="gudingdb ffffff">
				<view class="flexright">
					<view class="huisebtn" v-show="orderDetail.can_cancel" @click="cancelOrder(orderID)">取消订单</view>
					<view class="huangsebtn margin_left3" v-show="orderDetail.can_pay" @click="atoncePay">立即支付</view>
					<view class="huangsebtn margin_left3" v-show="orderDetail.can_receipt" @click="sureOrder(orderID)">确认已服务</view>
					<view class="huangsebtn margin_left3" v-show="orderDetail.can_comment" @click="estimate(orderID)">立即评价</view>
					<view class="huisebtn" v-show="orderDetail.can_del" @click.stop="deletorder(orderID)">删除订单</view>
				</view>
			</view>
		</view>
	</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				orderID: '', // 订单 id
				orderDetail: {
					seller:{
						avatar:""
					}
				}, // 订单详情内容
				pageshow: false,
				qrcodeurl: '',
				httpRequest
			}
		},
		onLoad(options) {
			let _this = this
			_this.orderID = options.id
		},
		onShow() {
			let _this = this
			_this.getOrderInfo()
		},
		methods: {
			// 获取订单详情
			getOrderInfo() {
				let _this = this
				httpRequest.request('/api/service_order/orderdetail', 'GET', {
					order_id: _this.orderID
				}).then(res => {
					if (res.code == 1) {
						_this.orderDetail = res.data
						this.pageshow = true
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			atoncePay(item){
				let data = {
					order_id:this.orderID,
					total_price:this.orderDetail.total_price
				}
				uni.redirectTo({
					url: "/pages_index/payment?msg4=" + encodeURIComponent(JSON.stringify(data))
				})
			},
			// 取消订单
			cancelOrder() {
				httpRequest.modal('提示', '确定取消当前订单吗？', true, (res) => {
					if (res) {
						httpRequest.request('/api/service_order/cancel', 'POST', {
							order_id: this.orderID,
						},  false, false, true).then(res => {
							httpRequest.toast(res.msg);
							if (res.code == 1) {
								this.getOrderInfo()
							}
						}).catch(err => {
							httpRequest.toast(err.msg);
						})
					}
				})
			},
			sureOrder(id){
				httpRequest.modal('提示', '确定当前服务已完成？', true, (res) => {
					if (res) {
						httpRequest.request('/api/service_order/receipt', 'POST', {
							order_id: id,
						}, false, false, true).then(res => {
							httpRequest.toast(res.msg);
							if (res.code == 1) {
								this.getOrderInfo()
							}
						}).catch(err => {
							httpRequest.toast(err.msg);
						})
					}
				})
			},
			// 跳转 立即评价
			estimate(id) {
				uni.navigateTo({
					url: "/pages_mine/reportEvaluate?type=2&id="+id
				})
			},
			deletorder(id) { //删除订单
				httpRequest.modal('提示', '确定删除当前订单吗？', true, (res) => {
					if (res) {
						httpRequest.request('/api/service_order/del', 'POST', {
							order_id:id,
						}, false, false, true).then(res => {
							httpRequest.toast(res.msg);
							if (res.code == 1) {
								setTimeout(() => {
									uni.navigateBack(1)
								}, 500)
							}
						}).catch(err => {
							httpRequest.toast(err.msg);
						})
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.imgShop {
		width: 26.62rpx;
		height: 24rpx;
	}

	.imgBox {
		width: 80rpx;
		height: 80rpx;
		border-radius: 8rpx 8rpx 8rpx 8rpx;
		border: 1rpx solid #F1F1F1;
		overflow: hidden;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.dan {
		width: 80vw;
		padding: 64rpx 40rpx 0rpx 40rpx;
	}

	.tuihuo {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #000000;
	}

	.money_tui {
		font-size: 28rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #D48B39;
	}

	.order {
		font-size: 28rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #000000;
	}

	.hexiao {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #000000;
	}

	.white {
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #999999;
	}

	.erwie {
		width: 169rpx;
		height: 169rpx;
	}

	.code {
		padding: 30rpx 30rpx;
		margin-top: 30rpx;
		background-color: #fff;
	}

	::v-deep.u-safe-area-inset-bottom {
		padding-bottom: 0;
		padding-bottom: constant(safe-area-inset-bottom);
	}

	.fuzhi {
		padding: 0rpx 100rpx;
	}

	.copy {
		padding: 20rpx 40rpx;
		border-radius: 51rpx;
		background-color: rgba(212, 139, 57, 1);
		margin-top: 109rpx;
		color: #fff;
	}

	.dan {
		padding: 64rpx 40rpx 64rpx 40rpx;
	}

	.zhongtong {
		margin-top: 87rpx;
		font-size: 32rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #000000;
		padding: 34rpx 82rpx;
		border: 1rpx solid rgba(223, 223, 223, 1);
		border-radius: 10rpx;
	}

	.wuliu {
		font-size: 40rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #000000;
	}

	.strongtext {
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #333333;
	}

	.bigtext {
		font-size: 34rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #333333;
	}

	.xzqianshu {
		font-size: 28rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: rgba(212, 139, 57, 1);
	}

	.huangsebtn {
		border: 2rpx solid rgba(243, 39, 28, 1);
		width: 170rpx;
		height: 67rpx;
		display: flex;
		border-radius: 120rpx;
		align-items: center;
		justify-content: center;
		font-size: 26rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: rgba(243, 39, 28, 1);
	}

	.huisebtn {
		border: 2rpx solid #666666;
		width: 170rpx;
		height: 67rpx;
		display: flex;
		border-radius: 120rpx;
		align-items: center;
		justify-content: center;
		font-size: 26rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #666666;
	}

	.shuliang {
		font-size: 26rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #999999;
	}

	.ershib {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #333333;
	}

	.shilitu {
		width: 134rpx;
		height: 128rpx;
		border-radius: 14rpx;
 overflow: hidden;
		image {
			width: 100%;
			height: 100%;
			border-radius: 14rpx;
		}
	}

	.qianshu {
		font-size: 28rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: rgba(243, 39, 28, 1);
	}

	.huisetext {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #666666;
	}

	.yhxiank {
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}

	.paddingbom {
		padding-bottom: 110rpx;
	}
</style>